<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>找出数组中相差最大的值</title>
</head>

<body>
  <script>
    function getMax(arr) {
      var min = arr[0], max = 0;
      for (var i = 0; i < arr.length; i++) {
        min = Math.min(min, arr[i]);
        max = Math.max(max, arr[i]);
      }
      return max - min;
    }
    console.log(getMax([1, 3, 5, 8]));
  </script>
</body>

</html>